package com.lzl.logdesenshelper.common;

import java.io.Serializable;

public class Response<T> implements Serializable {

    private static final long serialVersionUID = 8425143431019414926L;

    private T data;

    private Boolean success;

    private String errorCode;

    private String errorMsg;

    public static <T> Response<T> ofSuccess(T data) {
        Response<T> response = new Response<T>();
        response.setData(data);
        response.setSuccess(true);
        return response;
    }

    public static Response ofFail(ErrorResult errorResult){
        Response response = new Response();
        response.setSuccess(false);
        response.setErrorCode(errorResult.getCode());
        response.setErrorMsg(errorResult.getMsg());
        return response;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
}
